import 'package:flutter/material.dart';
import 'package:lib_common/components/widget/ntt_auto_size_text.dart';
import 'package:lib_common/components/widget/ntt_gesture_widget.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

/// 通用按钮 带渐变黄色与灰色 圆角
/// 可自定义修改激活颜色
class NttOrdinaryButton extends StatelessWidget {
  final double width;
  final double height;
  final double maxWidth;
  final double maxHeight;

  /// 按钮文本
  final String text;

  /// 文本颜色
  final Color textColor;

  /// 文字大小
  final double textSize;

  /// 圆角
  final double radius;

  /// 点击事件
  final Function()? onTap;

  /// 按钮外边距
  final EdgeInsetsGeometry? margin;

  /// 内边距
  final EdgeInsetsGeometry? padding;

  /// 激活状态
  final bool activationState;

  /// 是否显示边框 与激活状态互斥，启用边框时激活状态不生效
  final bool isShowBorder;

  /// 边框颜色
  final Color? borderColor;

  /// 边框宽度
  final double? borderWidth;

  /// 激活状态渐变背景 不设置会用默认的 设置了会优先使用这个
  final List<Color>? gradientColors;

  /// 背景颜色 设置了背景颜色则不会显示其他激活状态
  final Color? backgroundColor;

  /// 显示的子组件
  final Widget? child;

  const NttOrdinaryButton(
    this.text, {
    super.key,
    required this.width,
    required this.height,
    this.maxWidth = double.infinity,
    this.maxHeight = double.infinity,
    this.onTap,
    this.textColor = Colors.white,
    this.textSize = 20,
    this.radius = 30,
    this.activationState = true,
    this.margin,
    this.padding,
    this.isShowBorder = false,
    this.borderColor,
    this.borderWidth,
    this.gradientColors,
    this.backgroundColor,
    this.child,
  });

  @override
  Widget build(BuildContext context) {
    return NttGestureWidget(
      onTap: activationState ? onTap : null,
      behavior: HitTestBehavior.opaque,
      child: Container(
        constraints: BoxConstraints(
          minWidth: width,
          minHeight: height,
          maxWidth: maxWidth,
          maxHeight: maxHeight,
        ),
        // width: width,
        // height: height,
        margin: margin,
        padding: padding ?? EdgeInsets.symmetric(horizontal: 32.w),
        decoration: BoxDecoration(
          color: backgroundColor,
          border: isShowBorder
              ? Border.all(
                  color: borderColor ?? const Color(0xffFFD321),
                  width: borderWidth ?? 0.5,
                )
              : null,
          gradient: !isShowBorder && backgroundColor == null
              ? LinearGradient(
                  begin: Alignment.topCenter,
                  end: Alignment.bottomCenter,
                  colors: activationState
                      ? gradientColors == null
                          ? const [
                              Color(0xffFFD321),
                              Color(0xffFDAD30),
                            ]
                          : gradientColors!
                      : const [
                          Color(0xffE1E7ED),
                          Color(0xffADB6BF),
                        ],
                )
              : null,
          borderRadius: BorderRadius.circular(radius),
        ),
        alignment: Alignment.center,
        child: child ??
            NttAutoSizeText(
              text,
              style: TextStyle(
                color: textColor,
                fontSize: textSize,
              ),
            ),
      ),
    );
  }
}
